//
//  RNOLMyMessageCell.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/13.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLMyMessageCell.h"


@interface RNOLMyMessageCell ()
@property (nonatomic,strong) UIView *cellCardView;
@property (nonatomic,strong) UILabel *dateLabel;
@property (nonatomic,strong) UIButton *markButton;
@property (nonatomic,strong) UILabel *messageTitleLabel;
@property (nonatomic,strong) UILabel *contentLabel;
@property (nonatomic,strong) UIView * midlineView ;
@property (nonatomic,strong) UILabel *watchTipLabel;
@property (nonatomic,strong) UIImageView *rightIndicatorView;

@end


@implementation RNOLMyMessageCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = kBgColor;
        self.contentView.backgroundColor = kBgColor;
        self.translatesAutoresizingMaskIntoConstraints = NO;
        self.autoresizesSubviews = NO;
        
        [self addCellSubviews];
        [self layoutUIConfig];
    }
    return self;
}

- (void)addCellSubviews{
    [self.contentView addSubview:  self.cellCardView];
    [self.cellCardView addSubview: self.dateLabel];
    [self.cellCardView addSubview: self.markButton];
    [self.cellCardView addSubview: self.midlineView];
    [self.cellCardView addSubview: self.messageTitleLabel];
    [self.cellCardView addSubview: self.contentLabel];
    [self.cellCardView addSubview: self.watchTipLabel];
    [self.cellCardView addSubview: self.rightIndicatorView];
}

- (void)layoutUIConfig{

    [self.cellCardView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10, 18, 10, 18));
    }];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cellCardView.mas_top).with.offset(10);
        make.centerX.equalTo(self.cellCardView.mas_centerX);
        make.width.equalTo(@70);
        make.height.equalTo(@21);
    }];
    
    [self.markButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.dateLabel.mas_bottom).offset(25);
        make.left.equalTo(@10);
        make.width.height.equalTo(@20);
    }];

    [self.messageTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.markButton.mas_right).with.offset(15);
        make.right.equalTo(self.cellCardView).with.offset(-15);
        make.top.equalTo(self.dateLabel.mas_bottom).with.offset(20);
        make.height.equalTo(@30);
    }];
    

    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.messageTitleLabel);
        make.height.equalTo(@30);
        make.top.equalTo(self.messageTitleLabel.mas_bottom);
    }];

    [self.midlineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.markButton.mas_left).offset(10);
        make.right.equalTo(self.cellCardView).offset(0);
        make.height.equalTo(@1);
        make.top.equalTo(self.contentLabel.mas_bottom).offset(10);
    }];

    [self.watchTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentLabel.mas_left);
        make.width.equalTo(@60);
        make.height.equalTo(@21);
        make.top.equalTo(self.midlineView.mas_bottom).offset(15);
    }];

    [self.rightIndicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.cellCardView.mas_right).offset(-15);
        make.centerY.equalTo(self.watchTipLabel.mas_centerY);
        make.width.equalTo(@8);
        make.height.equalTo(@13);
    }];
}


- (UIView *)cellCardView{
    if (!_cellCardView) {
        _cellCardView = [UIView wgb_create:^(UIView *make) {
            make.backgroundColor = KWhiteColor;
            [make setLayerShadow:[KBlackColor colorWithAlphaComponent:0.5] offset:CGSizeMake(0, 1) radius: 3];
        }];
    }
    return _cellCardView;
}

- (UILabel *)dateLabel{
    if (!_dateLabel) {
        _dateLabel = [UILabel wgb_create:^(UILabel *make) {
            make.font = KFontSize(12);
            make.backgroundColor = RGB(221, 221, 221);
            make.textColor = RGB(255, 255, 255);
            [make setLayerShadow: [KBlackColor colorWithAlphaComponent:0.5] offset:CGSizeMake(0, 0) radius: 1];
            make.textAlignment = NSTextAlignmentCenter;
            make.text = @"4月13日";
        }];
    }
    return _dateLabel;
}


- (UIButton *)markButton{
    if (!_markButton) {
        _markButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_markButton setTitle:@"" forState:UIControlStateNormal];
        [_markButton setBackgroundColor: RGB(31, 161, 255) forState:UIControlStateNormal];
    }
    return _markButton;
}


- (UILabel *)messageTitleLabel{
    if (!_messageTitleLabel) {
        _messageTitleLabel = [UILabel wgb_create:^(UILabel *make) {
            make.font = KFontSize(15);
            make.textColor = kTextColor;
            make.text = @"线上充值成功! [系统消息]";
        }];
    }
    return _messageTitleLabel;
}

- (UILabel *)contentLabel{
    if (!_contentLabel) {
        _contentLabel = [UILabel wgb_create:^(UILabel *make) {
            make.font = KFontSize(14);
            make.textColor = RGB(153, 153, 153);
            make.text = @"您有一条新的消息,您卡余额已不足,请及时充值!";
        }];
    }
    return _contentLabel;
}

- (UIView *)midlineView{
    if (!_midlineView) {
        _midlineView = [UIView wgb_create:^(UIView *make) {
            make.backgroundColor = kBgColor ;
        }];
    }
    return _midlineView;
}

- (UILabel *)watchTipLabel{
    if (!_watchTipLabel) {
        _watchTipLabel = [UILabel wgb_create:^(UILabel *make) {
            make.font = KFontSize(12);
            make.textColor = kTextColor;
            make.text = @"点击查看";
        }];
    }
    return _watchTipLabel;
}

- (UIImageView *)rightIndicatorView{
    if (!_rightIndicatorView) {
        _rightIndicatorView = [UIImageView wgb_create:^(UIImageView *make) {
            make.image = [UIImage imageNamed:@"rnol_right_ arrow"];
        }];
    }
    return _rightIndicatorView;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
